package com.iphanta.community.common.utils;

import com.fasterxml.jackson.databind.JsonNode;

/**
 * @author 墨声 E-mail: zehong.hongframe.huang@gmail.com
 * create time: 4/21/22 3:01 PM
 */
public class BitMapUtils {

    public static int index(String uidParse) {
        /**
         * {"UID":"164208402300264449","timestamp":"2022-04-21 15:03:07","workerId":"495","sequence":"1"}
         */
        JsonNode json = JsonUtils.INSTANCE.toJson(uidParse);
        String timestamp = json.get("timestamp").textValue();
        String time = timestamp.split("\\s")[1];
        String[] hms = time.split(":");
        int sec = Integer.valueOf(hms[0]) * 60* 60 + Integer.valueOf(hms[1]) * 60 + Integer.valueOf(hms[2]);
        int seq = json.get("sequence").intValue();
        return sec * 1000 + seq;
    }

    public static String date(String uidParse) {
        JsonNode json = JsonUtils.INSTANCE.toJson(uidParse);
        String timestamp = json.get("timestamp").textValue();
        return timestamp.split("\\s")[0];
    }

}
